package wili.b1.transform;

import java.io.File;
import java.util.List;
import java.util.Map;

import wili.attrMapping._user.b1.AttConst;
import wili.attrMapping.file.JsonFile;
import wili.b1.transform.Conf.FILE;
import wili.b1.transform.Conf.Maping;
import wili.c.Ca;
import wili.c.File9a;
import wili.c.Misc9a;
import wili.json.JsonObj;

/**
 *
 */
class ValueA_to_valueB_ifHasSameValueC {

	public static void a_to_b_viaMapingConfig(String attName, String toName) {
		Map<String, String> mapingConfig = Misc9a.mapOf(Maping.typeToCtrlType);
		File from = FILE.from, to = FILE.to1;
		JsonFile json1 = new JsonFile(from);
		JsonFile json2 = new JsonFile(to);
		List<JsonObj> guidList = json1.findObjs_byAtt("guid", null);
		Ca.log(1, "guidList.size=" + guidList.size());
		int times = 0;
		for (JsonObj obj : guidList) {
			String guid = obj.valueOfSon("guid", null);
			JsonObj obj2 = json2.findObj_byAtt("guid", guid);
			if (obj2 == null)
				continue;
			String oldType = obj.valueOfSon("type", null);
			if (oldType == null)
				continue;
			String newType = mapingConfig.get(oldType);
			if (newType == null)
				newType = oldType;
			obj2.att(toName).setStringValue(newType);
			++times;
		}
		String st = json2.refreshJsonSt();
		File9a.str2file(st, to, -1);
		Ca.log(1, "update times=" + times);
	}

	public static void main(String[] args) {
		a_to_b_viaMapingConfig("type", AttConst.ctrlType);

	}
}
